import request from '../../utils/request';
const law = {
  state: {

  },

  getters: {

  },

  mutations: {

  },

  actions: {
    /**
     * 获取法律短剧列表
     * @payload{
     *  title  string 
     *  caseType string 
     *  pageNum string 
     * }
     * */ 
    GET_VIDEO_LIST({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.get('/caseVideo/list.htm', {
          params: payload
        }).then(res => {
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);  
          reject(err);
        })
      });
    },

    /**
     * 法律短剧-编辑短剧
     * @payload{
     *  id     string
     *  title  string 
     *  caseType string 
     *  videoUrl string 
     *  picUrl string 
     *  playCount string
     *  recommend string 是否推荐，1推荐 0不推荐
     *  state     string  状态，normal：正常，deleted：删除
     * }
     * */ 
    UPDATE_VIDEO({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/caseVideo/update.htm', payload).then(res => {
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);  
          reject(err);
        })
      });
    },

    /**
     * /caseVideo/save.htm
     * @payload{
     *  title  string 
     *  caseType string 
     *  videoUrl string 
     *  picUrl string 
     *  playCount string
     * }
     * */ 
    ADD_VIDEO({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/caseVideo/save.htm', payload).then(res => {
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);  
          reject(err);
        })
      });
    },

    /**
     * 法律短剧-详情
     * @payload{
     *  id  string 
     * }
     * */ 
    GET_VIDEO_DETAIL({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/caseVideo/detail.htm', payload).then(res => {
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);  
          reject(err);
        })
      });
    },

    /**
     * 获取法律知识列表
     * title string
     * caseType string 
     * knowledgeType string
     * pageNum string
     * */ 
    GET_KNOWLEDGE_LIST({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.get('/caseKnowledge/list.htm', {
          params: payload
        }).then(res => {
          console.log('res::', res);
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);  
          reject(err);
        })
      });
    },

    /**
     * 获取法律知识-知识类型列表
     * */ 
    GET_KNOWLEDGE_tYPE_LIST({ commit }) {
      return new Promise((resolve, reject) => {
        request.get('/caseKnowledge/typeList.htm').then(res => {
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);  
          reject(err);
        })
      });
    },

    /**
     * 法律知识-新建/更新/删除知识类型
     * @params payload{
     *  id: string  类型id ，为null新建，不为null更新
     *  name string  类型名称
     *  isDelete string 是否删除 1是0否
     *  remark string 备注
     * }
     * */ 
    HANDLE_KNOWLEDGE_TYPE({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/caseKnowledge/saveType.htm', payload).then(res => {
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);  
          reject(err);
        })
      });
    },

    /**
     * 法律知识-新增知识
     * @params payload{
     *  title string 
     *  caseType string 
     *  knowledgeType string 
     *  content string
     * }
    */
    ADD_KNOWLEDGE({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/caseKnowledge/save.htm', payload).then(res => {
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);  
          reject(err);
        })
      });
    },

     /**
     * 法律知识-更新/删除知识
     * @params payload{
     *  id string
     *  caseType string 
     *  knowledgeType string
     *  title string 
     *  content string
     *  recommend string  推荐与否  1是 0否
     *  state string 删除（deleted）
     * }
    */
    // UPDATE_KNOWLEDGE({ commit }, payload) {
    //   console.log('payLoad:::', payload);
    //   return new Promise((resolve, reject) => {
    //     request.post('/caseKnowledge/update.htm', payload).then(res => {
    //       console.log('commit::', commit);
    //       resolve(res);
    //     }).catch(err => {
    //       console.error('err::::', err);  
    //       reject(err);
    //     })
    //   });
    // },

     /**
     * 法律知识-详情
     * @params payload{
     *  id string
     * }
    */
    GET_KNOWLEDGE_DETAIL({ commit }, payload) {
      return new Promise((resolve, reject) => {
        request.post('/caseKnowledge/detail.htm', payload).then(res => {
          console.log('commit::', commit);
          resolve(res);
        }).catch(err => {
          console.error('err::::', err);  
          reject(err);
        })
      });
    },

  }
}

export default law